Ask Your Question
4

How to set resolution of video capture in python with Logitech c910 & c920

asked Sep 4 '12

Mike Lawrence gravatar image

I have two webcams, Logitech c910 and c920. When I use the python interface to opencv2.4.1 on Ubuntu 12.04, I cannot seem to change the width or height of the capture from either camera. For example, if I run the code:

import cv2
cam = cv2.VideoCapture(-1)
cam.read()

I get a 640x480 image/numpy array. However, if I try to run:

import cv2
cam = cv2.VideoCapture(-1)
cam.set(3,1920)
cam.set(4,1080)
cam.read()

I first get the printout False after each attempt to set the resolution, and then the console hangs when it gets to cam.read().

On the other hand, when I run the above on my mac, everything works fine and I get the expected 1920x1080 image/numpy array.

Getting this working with Ubuntu is really mission critical for me, so any help would be greatly appreciated!

Preview: (hide)

2 answers

Sort by » oldest newest most voted
2

answered Oct 5 '12

karlphillip gravatar image

Unfortunately, setting the size of the capture doesn't always work. One of the reasons being that sometimes the camera simply doesn't support the dimensions you are trying to set.

According to this thread, you can try to use the old python interface (something like this):

from opencv.cv import *  
from opencv.highgui import *

capture = cvCreateCameraCapture(0)

cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640)
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480)

If this approach doesn't work, you'll have to resize the captured frame yourself! Check cv2.resize()

Preview: (hide)
1

answered Aug 20 '13

NikolasE gravatar image

I have had the same problem and solved it by upgrading to the dev-version of opencv (2.9).

Preview: (hide)

Comments

This is because a fix was probably supplied. However it is weird it doesn't work for 2.4 then, since the version is influenced also. Maybe look for the corresponding bug report and mention that the fix doesn't work for 2.4.

StevenPuttemans gravatar imageStevenPuttemans (Aug 21 '13)edit

Question Tools

2 followers

Stats

Asked: Sep 4 '12

Seen: 73,547 times

Last updated: Aug 20 '13